# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=fdm
pkgver=2.2
pkgrel=1
pkgdesc="A simple lightweight tool of fetching, filtering and delivering emails"
url="https://github.com/nicm/fdm"
arch="all"
license="ISC"
makedepends="
	openssl-dev>3
	pcre2-dev
	tdb-dev
	zlib-dev
	"
subpackages="$pkgname-doc"
source="https://github.com/nicm/fdm/releases/download/$pkgver/fdm-$pkgver.tar.gz
	$pkgname-pcre2-fix.patch
	$pkgname-fix-use-after-free.patch
	$pkgname-send-utf8.patch
	"

prepare() {
	default_prepare
	# config.sub is too old to recognize loongarch64-alpine-linux-musl
	update_config_sub
}

build() {
	CFLAGS="$CFLAGS -flto=auto" \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--enable-pcre2
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
}

sha512sums="
13efa0f272c5f6146b90e094602e8a9b52016af79ae0b6cd80dc9f36b2ba37f64cadae7313bd8db90bcb007dd07206a3614987f11bb82c3535e04f0511c9fc6d  fdm-2.2.tar.gz
408da5b9ee9936fb198cdeb5bf3ad8e350845e9d0b009830d933cde0d5f8175c573a526ade42459ee32ddf7b1354a254c284214891f61afa16e71296bf53b71d  fdm-pcre2-fix.patch
e03a32770b9d8bc6e1c626bfd058ce1183f777d6b9a5cb01e3b0241074c02655f9a1d5d46452c9524a3403143df46d249a0493da30febb611409b1e148a43f45  fdm-fix-use-after-free.patch
901671822f3a41950112c7911e0cd354fbf003f43e00e3b73e67062f299e903306f050249c20046933d4642786592812b9574f217dc47dbb882f3b56558d9ec5  fdm-send-utf8.patch
"
